<?php
namespace app\index\controller;
use app\index\model\Level;
use app\index\model\Member;
use think\Controller;

/**
 * Created by PhpStorm.
 * User: jieai
 * Date: 2017-07-27
 * Time: 11:18
 */
class  LevelController extends Controller{
public function index(){


    return $this->fetch();
}

    public function getlist()
    {
        if (input('stime')&&input('dtime')){
            $record=Level::with('member')->whereTime('starttime','between',[input('stime'),input('dtime')])->where('status','<>','1')->order('createtime desc')->select();
        }
else{
    $record=Level::with('member')->where('status','<>','1')->order('createtime desc')->select();

}
        return json(['data'=>$record]);
}

    public function addlevel()

    {
        $memlist=Member::all();
        $this->assign('memlist',$memlist);
        return $this->fetch();
}

    public function postaddlevel()
    {
        $record=new Level();
        $record->member_id=input('member');
        $record->starttime=input('starttime');
        $record->stoptime=input('stoptime');
        $record->leixing=input('leixing');
        $record->beizhu=input('beizhu');

        if ($record->save()) {
            return $this->success('操作成功');
        }
        return $this->error('操作失败');

}

    public function deletebyid()
    {
        $levelrec=Level::get(input('id'));
        $levelrec->status=1;
        if ($levelrec->save()) {
            return $this->success('操作成功');
        }
        return $this->error('操作失败');
}

    public function pendbyid()
    {
        $levelrec=Level::get(input('id'));
        $levelrec->pend=1;
        if ($levelrec->save()) {
            return $this->success('操作成功');
        }
        return $this->error('操作失败');
    }
}